# Maintainer: Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=opencascade
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=7.4.0p1
pkgrel=2
pkgdesc='Open CASCADE Technology, 3D modeling & numerical simulation (mingw-w64)'
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-tk"
         "${MINGW_PACKAGE_PREFIX}-tcl"
         "${MINGW_PACKAGE_PREFIX}-freetype")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake")
optdepends=("${MINGW_PACKAGE_PREFIX}-intel-tbb"
            "${MINGW_PACKAGE_PREFIX}-freeimage"
            "${MINGW_PACKAGE_PREFIX}-gl2ps"
            "${MINGW_PACKAGE_PREFIX}-VTK")
license=('custom')
url='https://www.opencascade.org'
source=(http://files.salome-platform.org/Salome/other/${_realname}-${pkgver}.tar.gz)
md5sums=('7b875206d595c150ab547f1d4b721920')

build() {
  #Static Build
  [[ -d "${srcdir}/build-${MINGW_CHOST}-static" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}-static"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}-static" && cd "${srcdir}/build-${MINGW_CHOST}-static"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_LIBRARY_TYPE=STATIC \
    -DINSTALL_DIR_LAYOUT=Unix \
    ../${_realname}-${pkgver}

  ninja

  #Shared Build
  [[ -d "${srcdir}/build-${MINGW_CHOST}-shared" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}-shared"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}-shared" && cd "${srcdir}/build-${MINGW_CHOST}-shared"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_LIBRARY_TYPE=SHARED \
    -DINSTALL_DIR_LAYOUT=Unix \
    ../${_realname}-${pkgver}

  ninja
}

package() {
  #Static Install
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  DESTDIR=${pkgdir} cmake --build . --target install
  
  #Shared Install
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  DESTDIR=${pkgdir} cmake --build . --target install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE_LGPL_21.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

# vim: ts=2 sw=2 et:
